package com.atguigu.jsp.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(urlPatterns = "/Servlet03TestApplicationScope")
public class Servlet03TestApplicationScope extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、获取 ServletContext 对象
        ServletContext servletContext = getServletContext();

        // 2、把数据存入应用域
        servletContext.setAttribute("attrNameApp", "attrValueApp");

        // 3、重定向到目标页面
        response.sendRedirect("/pages/target.jsp");
    }
}
